package com.link.base.base.cachedtmanager.controller;

import com.link.base.cachedt.service.CacheDTService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 缓存数据：获取数据缓存时间，
 */

@RestController
@RequestMapping("/cacheDT")
public class CacheDTController {

    @Resource
    private CacheDTService cacheDTService;

    /**
     * 根据key获取缓存中数据最后更新时间
     *
     * @author guoshan
     * @date 2020年07月20日
     * @return
     */
    @RequestMapping(value = "/queryLastUpdateTimes")
    @ResponseBody
    public Map<String, Object> queryLastUpdTimes(@RequestBody List<String> cacheDataTimeKeys) {
        Map<String, Object> result = new HashMap<String, Object>(2);
        try {

            result.put("result",cacheDTService.queryDataUpdTimes(cacheDataTimeKeys));
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 根据key获取缓存中数据最后更新时间
     *
     * @author guoshan
     * @date 2020年07月20日
     * @return
     */
    @RequestMapping(value = "/hqueryLastUpdTime")
    @ResponseBody
    public Map<String, Object> hqueryLastUpdTime(String key, String field) {
        Map<String, Object> result = new HashMap<String, Object>(2);
        try {

            result.put("result",cacheDTService.hqueryDataUpdTime(key,field));
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 根据key获取缓存中数据最后更新时间
     *
     * @author guoshan
     * @date 2020年07月20日
     * @return
     */
    @RequestMapping(value = "/hgetAllqueryUpdTime")
    @ResponseBody
    public Map<String, Object> hgetAllqueryUpdTime(@RequestBody List<String>  key) {
        Map<String, Object> result = new HashMap<String, Object>(2);
        try {
            result.put("result",cacheDTService.hgetAllqueryUpdTime(key));
            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
